package org.budo.dubbo.protocol.http.dispatcher.websocket;

import java.io.InputStream;

import javax.websocket.Session;

import org.budo.dubbo.protocol.http.invocation.adapter.ProtocolResponse;
import org.budo.support.lang.util.IoUtil;

/**
 * @author li
 */
public class WebSocketProtocolResponse implements ProtocolResponse {
    private Session session;

    public WebSocketProtocolResponse(Session session) {
        this.session = session;
    }

    @Override
    public void addHeader(String name, String value) {
        throw new RuntimeException();
    }

    @Override
    public void write(InputStream inputStream) {
        String responseText = IoUtil.toString(inputStream);
        session.getAsyncRemote().sendText(responseText);
    }
}